<style lang="less">
  @import '../../styles/common.less';
</style>


<template>
  <div>
    <Table border :columns="columns" :data="data"></Table>
  </div>
</template>

<script>
  import moment from 'moment'
    export default {
        name: "stduent-info",
        data(){
          return{
            columns: [
              {
                title: '编号',
                key: 'id'
              },
              {
                title: '姓名',
                key: 'name'
              },
              {
                title: '手机号',
                key: 'telephone'
              },
              {
                title: '身份证',
                key: 'idCard'
              },
              {
                title: '课程名称',
                key: 'project'
              },
              {
                title: '审核状态',
                key: 'state',
                render:function (h,params) {
                  console.log(params);
                  return h('div',
                    params.row.state == 1 ? '审核通过' : params.row.state == 0 ? '未审核' : '审核不通过'
                  )
                }
              },
              {
                title: '提交时间',
                key: 'createTime',
                render:function (h,params) {
                  console.log(params);
                  return h('div',
                    moment(params.row.createTime).format('YYYY-MM-DD HH:mm:ss'));
                }
              },
              {
                title: '操作',
                key: 'action',
                width: 200,
                align: 'center',
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      on: {
                        click: () => {
                          this.show1(params.index)
                        }
                      }
                    }, '查看'),
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px'
                      },
                      on: {
                        click: () => {
                          this.show(params.index)
                        }
                      }
                    }, '审核'),
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      on: {
                        click: () => {
                          this.remove(params.index)
                        }
                      }
                    }, '删除')
                  ]);
                }
              }
            ],
            data: [

            ]
          }
        },
        methods:{
          add(){
            this.$router.push({
              name: 'add_stduent'
            });
          },
          init(){
            this.$http.get('/school/allStduent').then(res => {
              this.data = res.data.data;
            });
          },
          show1 (index) {
            this.$Modal.confirm({
              title: '查看信息',
              content: `姓名：${this.data[index].name}<br>性别：${this.data[index].sex == 1 ? '男' : '女'}<br>手机号：${this.data[index].telephone}<br>身份证：${this.data[index].idCard}
                        <br>班级名：${this.data[index].className}<br>学院名：${this.data[index].collegeName}<br>课程名：${this.data[index].project}<br>
                        所属公司：${this.data[index].company}<br>
                        职级：${this.data[index].rank}<br>
                        工作年限：${this.data[index].workingTime}<br>
                        备注：${this.data[index].remark}<br>申请时间：${this.data[index].createTime}`
            })
          },
          show (index) {
            this.$Modal.confirm({
              title: '审核信息',
              content: `姓名：${this.data[index].name}<br>性别：${this.data[index].sex == 1 ? '男' : '女'}<br>手机号：${this.data[index].telephone}<br>身份证：${this.data[index].idCard}
                        <br>班级名：${this.data[index].className}<br>学院名：${this.data[index].collegeName}<br>课程名：${this.data[index].project}<br>
                        所属公司：${this.data[index].company}<br>
                        职级：${this.data[index].rank}<br>
                        工作年限：${this.data[index].workingTime}<br>
                        备注：${this.data[index].remark}<br>申请时间：${this.data[index].createTime}`,
              okText:'审核通过',
              cancelText:'审核不通过',
              onOk: () => {
                this.$http.post('/school/updStdState',{id:this.data[index].id,state:1}).then(res =>{
                  this.$Message.info('更新完成');
                  this.init();
                });
              },
              onCancel: () => {
                this.$http.post('/school/updStdState',{id:this.data[index].id,state:2}).then(res =>{
                  this.$Message.info('更新完成');
                  this.init();
                });
              }
            })
          },
          remove (index) {
            this.$http.get('/school/delStudent?id='+this.data[index].id).then(res =>{
              this.$Message.info('删除成功');
              this.data.splice(index, 1);
            });
          }
        },
        mounted(){
          this.init();
        }
    }
</script>

<style scoped>

</style>
